/*****************************************************************
 MYD Engine v0.1

 File: myd_input.cpp
 Created: 09/07/09
*****************************************************************/

#include "myd_input.h"
//------------------------------------------------------------------------------
using namespace myd;
//------------------------------------------------------------------------------
Input::Input()
{
	Reset();

	//Tomamos la posicion actual del mouse, esto se esta haciendo mediante winapi, 
	//lo logico seria mudarlo a DirectInput

	POINT CursorPos;
	GetCursorPos(&CursorPos);

	m_alMouseScreenAbsPos[0] = CursorPos.x;
	m_alMouseScreenAbsPos[1] = CursorPos.y;
	m_alMouseScreenAbsPos[2] = 0;
}
//------------------------------------------------------------------------------
Input::~Input()
{
}
//------------------------------------------------------------------------------
void Input::UpdateMouse()
{
	//update the mouse buttons data based on the previous acquire data
	for(int b=0;b<3;b++)
	{
		if(m_aucMouseBut[b])
		{
			if(!m_abButState[b])
			{
				m_abMouseButClick[b]=true;
				m_abButState[b]=true;
			}
			else { m_abMouseButClick[b]=false; }
		}
		else { if(m_abButState[b]) { m_abButState[b]=false; } }
	}
}
//------------------------------------------------------------------------------
void Input::UpdateKeyboard()
{
	//update the key events data based on the previous acquire data
	for(int k=0; k<256; k++)
	{
		if(KeyBuffer[k] != KeyPrevBuffer[k])
		{
			if(GetKeyDown(k)) 	{ KeyEvent[k] = KS_DOWN; }
			else 				{ KeyEvent[k] = KS_UP; }
		}
		else { KeyEvent[k] = KS_NONE; }
	}
}
//------------------------------------------------------------------------------
void Input::SetMousePos(long x, long y, long z)
{
	m_alMouseRelPos[POS_X] = x - m_alMouseScreenAbsPos[POS_X];
	m_alMouseRelPos[POS_Y] = y - m_alMouseScreenAbsPos[POS_Y];
	m_alMouseRelPos[POS_Z] = z - m_alMouseScreenAbsPos[POS_Z];

	m_alMouseScreenAbsPos[POS_X] = x;
	m_alMouseScreenAbsPos[POS_Y] = y;
	m_alMouseScreenAbsPos[POS_Z] = z;
}
//------------------------------------------------------------------------------
void Input::EventClean() {ZeroMemory(&KeyEvent, sizeof(KeyEvent));}

//------------------------------------------------------------------------------
void Input::Reset()
{
	ZeroMemory(&KeyBuffer, sizeof(KeyBuffer));
	ZeroMemory(&KeyPrevBuffer, sizeof(KeyPrevBuffer));
	ZeroMemory(&KeyEvent, sizeof(KeyEvent));

	for(int eje=0; eje<3; eje++)
	{
		m_alMouseScreenAbsPos[eje] = 0;
		m_alMouseRelPos[eje] = 0;
		m_aucMouseBut[eje] = 0;
		m_abMouseButClick[eje] = false;
		m_abButState[eje] = false;
	}
}
//------------------------------------------------------------------------------
